| 1 |  |  | /* jshint -W101, -W098 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | var assert = require('assert'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | var BtccomConverter = require("../lib/btccom.convert"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | var network = { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |     messagePrefix: '\u0018Bitcoin Signed Message:\n', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |     bech32: 'bc', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     bip32: { public: 76067358, private: 76066276 }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     pubKeyHash: 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     scriptHash: 5, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     wif: 128 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | var useNewCashAddr = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | var converter = new BtccomConverter(network, useNewCashAddr); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | describe("btccom.convert", function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     describe("convertBlock", function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         it("works", function(cb) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |             var input = require('./test_data/btccomconvert.block'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |             var output = converter.convertBlock(input.data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |             // assert fields match | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |                 ["height", "height"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |                 ["is_orphan", "is_orphan"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |                 ["merkleroot", "mrkl_root"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |                 ["hash", "hash"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |                 ["prev_block", "prev_block_hash"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                 ["next_block", "next_block_hash"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 ["transactions", "tx_count"] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             ].forEach(function(keyAssoc) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                 var blocktrailKey = keyAssoc[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                 var btccomKey = keyAssoc[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                 assert.ok(blocktrailKey in output); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |                 assert.ok(input.data[btccomKey] === output[blocktrailKey]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             cb(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     describe("convertBlockTxs", function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         it("works", function(cb) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             var input = require('./test_data/btccomconvert.blocktxs'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             var output = converter.convertBlockTxs(input); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             assert.ok("current_page" in output); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             assert.ok("per_page" in output); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             assert.ok("total" in output); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             // assert fields match | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 ["size", "size"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                 ["hash", "hash"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 ["confirmations", "confirmations"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 ["is_coinbase", "is_coinbase"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 ["total_fee", "fee"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 ["size", "size"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                 ["is_double_spend", "is_double_spend"] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             ].forEach(function(keyAssoc) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 var blocktrailKey = keyAssoc[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                 var btccomKey = keyAssoc[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                 var blockTx = output.data[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                 assert.ok(blocktrailKey in blockTx); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                 assert.ok(input.data.list[0][btccomKey] === blockTx[blocktrailKey]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             cb(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     describe("convertTx", function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         it("works", function(cb) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             var input = require('./test_data/btccomconvert.tx'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             var output = converter.convertTx(input); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             assert.ok("hash" in output); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             // assert fields match | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                 ["size", "size"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                 ["hash", "hash"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                 ["confirmations", "confirmations"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                 ["is_coinbase", "is_coinbase"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                 ["block_height", "block_height"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                 ["total_fee", "fee"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                 ["size", "size"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                 ["is_double_spend", "is_double_spend"] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             ].forEach(function(keyAssoc) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                 var blocktrailKey = keyAssoc[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                 var btccomKey = keyAssoc[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                 var blockTx = output; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                 assert.ok(blocktrailKey in blockTx); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                 assert.ok(input.data[btccomKey] === blockTx[blocktrailKey]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             cb(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     describe("convertAddress", function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         it("works", function(cb) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             var input = require('./test_data/btccomconvert.address'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             var output = converter.convertAddress(input); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             // assert fields match | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |                 ["address", "address"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |                 ["balance", "balance"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |                 ["received", "received"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                 ["sent", "sent"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |                 ["transactions", "tx_count"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |                 ["unconfirmed_received", "unconfirmed_received"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                 ["unconfirmed_sent", "unconfirmed_sent"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |                 ["unconfirmed_transactions", "unconfirmed_tx_count"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                 ["first_tx", "first_tx"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |                 ["last_tx", "last_tx"] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             ].forEach(function(keyAssoc) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                 var blocktrailKey = keyAssoc[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                 var btccomKey = keyAssoc[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |                 assert.ok(blocktrailKey in output, blocktrailKey); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                 assert.ok(input.data[btccomKey] === output[blocktrailKey], blocktrailKey); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             cb(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     }); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |     describe("convertAddressTxs", function() { | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |         it("works", function(cb) { | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |             var input = require('./test_data/btccomconvert.addresstxs'); | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |             var output = converter.convertAddressTxs(input); | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |             assert.ok("total" in output); | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |             cb(); | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |         }); | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     describe ("convertAddressUnspentOutputs", function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         it("works", function(cb) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |             var input = require('./test_data/btccomconvert.addressutxos'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |             var output = converter.convertAddressUnspentOutputs(input, "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |             // assert fields match | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |                 ["hash", "tx_hash"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |                 ["confirmations", "confirmations"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |                 ["value", "value"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |                 ["index", "tx_output_n"] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             ].forEach(function(keyAssoc) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |                 var blocktrailKey = keyAssoc[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |                 var btccomKey = keyAssoc[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |                 var blockTx = output.data[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |                 assert.ok(blocktrailKey in blockTx); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |                 assert.ok(input.data.list[0][btccomKey] === blockTx[blocktrailKey]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |             assert.ok("total" in output); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             cb(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 176 |  |  |  |